<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core"  prefix="c"%>
<%@ taglib prefix="f" uri="http://www.springframework.org/tags/form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%
	String path=request.getContextPath();
%>    

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
	<link href="/resources/css/bootstrap-4.3.1/css/bootstrap.css" rel="stylesheet">
	<script type="text/javascript" src="/resources/js/jquery-3.2.1/jquery.js"></script>
	<script type="text/javascript" src="/resources/js/jqueryvalidate/jquery.validate.js"></script>
	<script type="text/javascript" src="/resources/js/jqueryvalidate/localization/messages_zh.js"></script>
	<script type="text/javascript" src="/resources/css/bootstrap-4.3.1/js/bootstrap.js"></script>
</head>
<body>


				<form action="add" method="post" name = "addStu">
				  
				  <div class="form-group">
				    <label for="exampleInputPassword1">学生姓名</label>
				    <input type="text" class="form-control" name = "name">
				  </div>
				  
				  
				  <c:forEach items="${listMaj }" var="major">
				  
				  
					  <div class="form-group form-check">
					    <input type="checkbox" class="form-check-input" name = "ids" value = "${major.id }">
					    <label class="form-check-label" for="exampleCheck1">${major.name }</label>
					  </div>
				  
				  </c:forEach>
				 省 
				  <select class = "province" name = "provinceId">
				  	
				  </select>
				市
				  <select class = "city" name = "cityId"></select>
				  
				县
				  <select class = "county" name = "countyId"></select>
				
				  
				  
				  		  
				  <input type = "button" class="btn btn-primary" onclick = "submitForm()" value = "添加">
				</form>
			<script type="text/javascript">
			
			/* function submitForm(){
				$("form[name=addStu]").ajaxSubmit(function(msg){
					
					if(msg > 0){
						
						alert("添加成功！");
						location = "/";
						
					}	else{
						alert("添加失败！");
						
					}		
					
				})
				
			} */

			
			showArea("province",0);
			
			$(".province").change(function(){
				
				var node = $(".province").val();
				
				$(".city").empty();
				
				showArea("city", node);
				
			})
			$(".city").change(function(){
				
				var node = $(".city").val();
				
				$(".county").empty();
				
				showArea("county", node);
				
			})
			
			function showArea(areaName,pid){
				
				$.post("findAreaById",{pid:pid},function(msg){
					
					console.log(msg);
					for(var i in msg){
						$("."+areaName+"").append("<option value="+msg[i].id+">"+msg[i].name+"</option>");
							
					}
					
				},"json")	
			}
			
			
			
			
			 function submitForm(){
				$.post("add",$("form[name=addStu]").serialize(),function(msg){
					
					if(msg > 0){
						alert("添加成功");
						location = "/";
					}else{
						alert("添加失败");
					}
					
				})
				
			} 
				
		
			</script>
	
		
</body>
</html>